package com.example.casper.Experiment2024.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.casper.Experiment2024.R;

public class WebViewFragment extends Fragment {
    private WebView webView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_web_view, container, false);
        webView = view.findViewById(R.id.web_view);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        // 显示暨珠的搜索页面
        webView.loadUrl("https://www.baidu.com/s?wd=%E6%9A%A8%E5%8D%97%E5%A4%A7%E5%AD%A6%E7%8F%A0%E6%B5%B7%E6%A0%A1%E5%8C%BA");
        return view;
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        // 释放WebView资源
        if (webView != null) {
            webView.destroy();
        }
    }
}